<?
// /ui/commandhandler/request/group|renew|restore/group/[groupname][/status/ok]

class News_Command_QueueHandler
{
    var $Controller; 
    var $PID; 
    function News_Command_QueueHandler($controller)
	{
	    $this->Controller = $controller; 
        $this->Id         = $this->Controller->Settings['id']; 
        $this->Group      = $this->Controller->Settings['group']; 
        $this->Path       = "notify/{$this->Group}.{$this->Id}.kill";
        $this->URI        = $this->Controller->URI (array('status'=>'ok'));
	}
	
	function GetURI()
	{ 
	    $uri = $this->Controller->URI (array('ui'=>'queue', 'request'=>'list'));
	    return array("RequestURI"  => $this->URI,
	                 "RedirectURI" => $uri);
	}
	
	function GetStatus()
	{ 
	    return 'OK';
	}
	
	function Display()
	{   
	}
	
	function Signal()
	{  
        $message = $this->Group; 
        if (strlen($this->Controller->Settings['status']) > 0)
        {
            return $this->GetStatus ();
        } 
        $this->Controller->Save($this->Path, $message); 
        return $this->Controller->Dialog ($this->GetURI()); 
	} 
	
	function Invoke($command)
	{  
	
	    $this->Path = $command['path']; 
        $id = $command['arg1'];
        
        
        echo $id . "\n";
        echo $command['type'] . "\n";
        echo $this->Path . "\n";
        
	    if ($command['type'] == 'kill')
	    {
	        echo "Killing queue for {$id}\n";
	        $this->Controller->Queue->Dispose($id);
		    unlink ($this->Path); 
	        return;
	    }
	    if ($this->Controller->Queue->Recall($id)) 
	    {
	        echo "Starting queue for {$id}\n";
	        $this->Controller->Queue->Start();
	    } 
	    else
	    {
	        echo "*** ERROR: Could not locate queue #{$id}\n";
	    }
		unlink ($this->Path); 
	}
     
}



